package org.tech4j.springboot.starter.edi.alarm.common;

import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.tech4j.edi.alarm.api.AlarmHandler;
import org.tech4j.edi.alarm.api.config.AlarmConfig;
import org.tech4j.edi.alarm.base.handler.RetryErrorAlarmHandler;
import org.tech4j.edi.persistence.api.RetryRecordPersistService;
import org.tech4j.springboot.starter.edi.persistence.common.EdiPersistenceConfiguration;

/**
 * @program: tech4j
 * @description:
 * @author: YuKai Fan
 * @create: 2025/3/10 15:41
 **/
@Configuration
@AutoConfigureAfter(EdiPersistenceConfiguration.class)
public class EdiAlarmCommonConfiguration {

    @Bean
    @ConditionalOnBean(RetryRecordPersistService.class)
    public AlarmHandler retryErrorAlarmHandler(
            final AlarmConfig alarmConfig,
            final RetryRecordPersistService retryRecordPersistService) {
        return new RetryErrorAlarmHandler(alarmConfig, retryRecordPersistService);
    }

    @Bean
    @ConfigurationProperties(prefix = "tech4j.edi.alarm")
    public AlarmConfig alarmConfig() {
        return new AlarmConfig();
    }
}
